home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / xlib / xlib06p2 / xpal.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-22  |  4.1 KB  |  168 lines

  1. #include "xinternl.h"
  2. #include <conio.h>
  3. #include <mem.h>
  4.  
  5. /*==================================================================
  6. XPAL.CPP contains the basic variables and functions for palette
  7. handling.
  8.  
  9. These routines were written initially by Themie Gouthas and
  10. company and modified March 1995 by Victor B. Putz.
  11. ===================================================================*/
  12.  
  13.  
  14. void  x_get_pal_raw(       /* Read DAC palette into raw buffer       */
  15.   BYTE * pal,
  16.   int num_colrs,
  17.   int start_index
  18. )
  19. {
  20.   BYTE * pb = pal;// + ( start_index * 3 );
  21.   outp( DAC_READ_INDEX, start_index );
  22.   //multiply num_colrs by 3 to get number of bytes to get
  23.   num_colrs *= 3;
  24.   while ( num_colrs-- ) {
  25.     *pb++ = ( BYTE )inp( DAC_DATA );
  26.   }
  27. }
  28.  
  29. void  x_get_pal_struc(     /* Read DAC palette into annotated buffer */
  30.   BYTE  * pal,
  31.   int num_colrs,
  32.   int start_index
  33. )
  34. {
  35.   *pal++ = ( BYTE )start_index;
  36.   *pal++ = ( BYTE )num_colrs;
  37.   x_get_pal_raw( pal, num_colrs, start_index );
  38. }
  39.  
  40.  
  41.  
  42. inline void WaitVsyncStart(
  43.   void
  44. )
  45. {
  46.   while( inp( INPUT_STATUS_0 ) & 0x08 );
  47.   while( !( inp( INPUT_STATUS_0 ) & 0x08 ) );
  48. }
  49.  
  50. void  x_put_pal_raw(       /* Write DAC palette from raw buffer      */
  51.   BYTE * pal,
  52.   int num_colrs,
  53.   int start_index)
  54. {
  55.  BYTE * pb = pal;// + ( start_index * 3 );
  56.  WaitVsyncStart();
  57.  outp( DAC_WRITE_INDEX, start_index );
  58.  //multiply num_colrs by 3 to get number of bytes to get
  59.  num_colrs *= 3;
  60.  while( num_colrs-- ) {
  61.    outp( DAC_DATA, *pb++ );
  62.  }
  63. }
  64.  
  65.  
  66. void  x_put_pal_struc(     /* Write DAC palette from annotated buffer*/
  67.   BYTE * pal
  68. )
  69. {
  70.   x_put_pal_raw( pal + 2, *(pal + 1), *pal );
  71. }
  72.  
  73. void  x_set_rgb(                /* Set the RGB components of a color index*/
  74.   BYTE color,
  75.   BYTE red_c,
  76.   BYTE green_c,
  77.   BYTE blue_c
  78. )
  79. {
  80.   outp( DAC_WRITE_INDEX, color );
  81.   outp( DAC_DATA, red_c );
  82.   outp( DAC_DATA, green_c );
  83.   outp( DAC_DATA, blue_c );
  84. }
  85.  
  86. void  x_rot_pal_raw(           /* Rotate a raw palette buffer             */
  87.   BYTE  * pal,
  88.   int direction,
  89.   int num_colrs
  90. )
  91. {
  92.         //decrement num_colrs, since we're only moving ( num_colrs - 1 ) in the block.
  93.         num_colrs--;
  94.         switch ( direction ) {
  95.         case 0 : {
  96.       int iRed = *pal;
  97.       int iGreen = *( pal + 1 );
  98.       int iBlue = *( pal + 2 );
  99.       memmove( pal, pal + 3, num_colrs * 3 );
  100.       pal += num_colrs * 3;
  101.       *( pal + 0 ) = ( BYTE )iRed;
  102.       *( pal + 1 ) = ( BYTE )iGreen;
  103.       *( pal + 2 ) = ( BYTE )iBlue;
  104.     }
  105.                 break;
  106.     case 1 : {
  107.       int iRed = *( pal + ( num_colrs * 3 ) );
  108.       int iGreen = *( pal + ( num_colrs * 3 ) + 1 );
  109.       int iBlue = *( pal + ( num_colrs * 3 ) + 2 );
  110.       memmove( pal + 3, pal, num_colrs * 3 );
  111.       *( pal + 0 ) = ( BYTE )iRed;
  112.       *( pal + 1 ) = ( BYTE )iGreen;
  113.       *( pal + 2 ) = ( BYTE )iBlue;
  114.     }
  115.     break;
  116.   }
  117. }
  118.  
  119. void  x_rot_pal_struc(    /* Rotate an anottated palette buffer      */
  120.   BYTE  * pal,
  121.   int direction
  122. )
  123. {
  124.   x_rot_pal_raw( pal + 2, direction, *(pal + 1) );
  125. }
  126.  
  127. WORD  x_cpcontrast_pal_struc(     /* Copy and contrast adjust annotated  */
  128.   BYTE  *src_pal,  /*  palette buffer                     */
  129.   BYTE  *dest_pal,
  130.   BYTE Intensity
  131. )
  132. {
  133.   int iDelta = ( 0xff - Intensity ) & 0x7f;
  134.   //copy start and number of colors
  135.   int iStartColor = *dest_pal++ = *src_pal++;
  136.   int iNumColors = *dest_pal++ = *src_pal++;
  137. //  src_pal += ( iStartColor * 3 );
  138. //  dest_pal += ( iStartColor * 3 );
  139.   WORD wFlag = 0;       //returns zero if all colors are zero
  140.   for( int i = 0; i < iNumColors * 3; ++i ) {
  141.     int iTemp = *src_pal++;
  142.     iTemp -= iDelta;
  143.     if ( iTemp < 0 ) {
  144.       iTemp = 0;
  145.     }
  146.     if ( iTemp > 0 ) {
  147.       wFlag = 1;
  148.     }
  149.     *dest_pal++ = ( BYTE )iTemp;
  150.   }
  151.   return wFlag;
  152. }
  153.  
  154. void  x_transpose_pal_struc(  /* Write DAC palette from annotated type*/
  155.   BYTE  * pal, /* buffer with a new offset             */
  156.   int StartColor)
  157. {
  158.  
  159. }
  160.  
  161.  
  162. void  x_put_contrast_pal_struc( /* Write DAC palette from annotated */
  163.   BYTE  * pal,   /* type buffer with specified intensity  */
  164.   BYTE  intensity)
  165. {
  166.  
  167. }
  168.